package tmproject.hlhj.fhp.cartrans.activitys

import android.graphics.Bitmap
import com.cjt2325.cameralibrary.JCameraView
import com.cjt2325.cameralibrary.listener.ClickListener
import com.cjt2325.cameralibrary.listener.JCameraListener
import kotlinx.android.synthetic.main.aty_camera.*
import org.greenrobot.eventbus.EventBus
import tmproject.hlhj.fhp.cartrans.BaseAty
import tmproject.hlhj.fhp.cartrans.IView.CameraView
import tmproject.hlhj.fhp.cartrans.R
import tmproject.hlhj.fhp.cartrans.event.PathEvent
import tmproject.hlhj.fhp.cartrans.javaBean.SaveEvent
import tmproject.hlhj.fhp.cartrans.presenter.CameraPresenter
import tmproject.hlhj.fhp.cartrans.utils.FileUtils

/**
 * Created by Never Fear   on 2018\9\28 0028.
Never More....
 */
class CameraAty :BaseAty<CameraView,CameraPresenter>(), CameraView {
    override fun bindView(): CameraView {
        return this
    }

    override fun createPresenter(): CameraPresenter {
        return CameraPresenter()
    }

    override fun getContentId(): Int {
        return R.layout.aty_camera
    }

    override fun initView() {
        //权限检查
        camera.setTip("")
        //设置只能录像或只能拍照或两种都可以（默认两种都可以）
        camera.setFeatures(JCameraView.BUTTON_STATE_ONLY_CAPTURE);
        //设置视频质量
        camera.setMediaQuality(JCameraView.MEDIA_QUALITY_MIDDLE);
        //回调
        camera.setJCameraLisenter(object : JCameraListener {
            override fun recordSuccess(url: String?, firstFrame: Bitmap?) {

            }

            override fun captureSuccess(bitmap: Bitmap?) {
                val pathEvent = PathEvent()
                pathEvent.path=FileUtils.createImageFile(bitmap!!,this@CameraAty).path
                EventBus.getDefault().post(pathEvent)
                finish()
            }
        });
//左边按钮点击事件
        camera.setLeftClickListener(object : ClickListener {
            override fun onClick() {
                finish()
            }
        });
    }

    override fun logicStart() {
    }

    override fun setListener() {
    }
}